"""
    create by IAmFiveHigh on 2023/9/6
"""


class Node:
    def __init__(self, element):
        self.e = element
        self.next = None

    def __str__(self):
        return f"Node: [{self.e}]"


class LinkListQueue:
    def __init__(self):
        self._head = None
        self._tail = None
        self._size = 0

    def get_size(self):
        return self._size

    def is_empty(self):
        return self._size == 0

    def enqueue(self, element):
        if self.is_empty():
            self._tail = Node(element)
            self._head = self._tail

        else:
            self._tail.next = Node(element)
            self._tail = self._tail.next
        self._size += 1

    def dequeue(self):
        if self.is_empty():
            raise Exception("队列为空")
        elif self.get_size() == 1:
            return_node = self._head
            self._tail = None
            self._head = None
            self._size -= 1
            return return_node.e
        else:
            return_node = self._head
            self._head = self._head.next
            return_node.next = None
            self._size -= 1
            return return_node.e

    def __str__(self):
        description = "Queue: "
        cur = self._head
        while cur is not None:
            description += f"{str(cur.e)} -> "
            cur = cur.next
        description += "None"
        return description
